package com.jetpack_sunflower.data

import androidx.lifecycle.LiveData
import androidx.room.*

@Dao
interface GardenPlantingDao {

    @Query("select * from garden_plantings")
    fun getGardenPlantings(): LiveData<List<GardenPlanting>>


    @Query("select * from garden_plantings where id = :gardenPlantingId")
    fun getGardenPlanting(gardenPlantingId: Long): LiveData<GardenPlanting>

    @Query("select * from garden_plantings where plant_id = :plantId")
    fun getGardenPlantingForPlant(plantId: String): LiveData<GardenPlanting>

    @Transaction
    @Query("select * from plant")
    fun getPlantAndGardenPlantings(): LiveData<List<PlantAndGardenPlantings>>

    @Insert
    fun insertGardenPlanting(gardenPlanting: GardenPlanting): Long

    @Delete
    fun deleteGardenPlanting(gardenPlanting: GardenPlanting)
}

/**
 * @Query("SELECT * FROM garden_plantings")
fun getGardenPlantings(): LiveData<List<GardenPlanting>>

@Query("SELECT * FROM garden_plantings WHERE id = :gardenPlantingId")
fun getGardenPlanting(gardenPlantingId: Long): LiveData<GardenPlanting>

@Query("SELECT * FROM garden_plantings WHERE plant_id = :plantId")
fun getGardenPlantingForPlant(plantId: String): LiveData<GardenPlanting>

/**
 * This query will tell Room to query both the [Plant] and [GardenPlanting] tables and handle
 * the object mapping.
*/
@Transaction
@Query("SELECT * FROM plants")
fun getPlantAndGardenPlantings(): LiveData<List<PlantAndGardenPlantings>>

@Insert
fun insertGardenPlanting(gardenPlanting: GardenPlanting): Long

@Delete
fun deleteGardenPlanting(gardenPlanting: GardenPlanting)
 */
